package bytezero.threadexer;

/**
 * 创建 三个窗口 买票  总票数为 100张  使用实现Runnabel接口的方式
 *
 * @author Bytezero1·zhenglei!    Email:420498246@qq.com
 * create  2021-10-15 18:11
 */

class window2 implements  Runnable{

    private int ticket = 100;  //Runnable 里面共用一个   private int ticket = 100;
    @Override
    public void run() {
        while(true){
            if(ticket >0){
                System.out.println(Thread.currentThread().getName()+ ":买票，票号为："+ticket);
                ticket--;
            }else{
                break;
            }
        }
    }
}

public class WindowTest2 {
    public static void main(String[] args) {
        window2 w2 = new window2();  //一个对象 放入了三个 构造器中，共用了 100

        Thread t1 = new Thread(w2);
        Thread t2 = new Thread(w2);
        Thread t3 = new Thread(w2);

        t1.setName("窗口一");
        t2.setName("窗口二");
        t3.setName("窗口三");

        t1.start();
        t2.start();
        t3.start();
    }
}
